package com.xuzimian.global.demo.spring.security.oauth2.client.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {


    @RequestMapping("/logout")
    public String signout(HttpServletRequest request) throws Exception{
        request.logout();
        return "deny";
    }

    @RequestMapping("/")
    public String home(){
        return "index";
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }


    /**
     * 返回用户已经登录的 Token,可用于从资源服务器获取资源时需要的access_token参数凭证。
     * 其中tokenValue 就是access_token，其值是jwt形式的。
     * @return
     */
    @RequestMapping("/getLoginedToken")
    @ResponseBody
    public Authentication getLoginedToken(){
        Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
        return authentication;
    }



}
